package com.project.dao.tags;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.project.dao.BaseDao;
import com.project.entity.sys.SelectTag;


/**
 * @author kale
 * A dao interface for generate select input widget.
 */
@Repository
@SuppressWarnings("unchecked")
public class HibernateWidgetDAO extends BaseDao implements WidgetDAO{

	@Override
	public List<Map<String, String>> getSelectOptions(String selectId) {
		String queryString = "from SelectTag where selectId=? and status=1 order by labelSeq";
		List<SelectTag> selectTag = find(queryString, selectId);
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (int i = 0; i < selectTag.size() ; i++) {
			SelectTag st = selectTag.get(i);
			Map<String, String> map = new HashMap<String, String>();
			map.put(st.getLabel(), st.getValue());
			list.add(map);
		}
		return list;
	}

	@Override
	public Map<String, List<Map<String, String>>> getAllDic() {
		Map<String,List<Map<String,String>>> dicMap=new HashMap<String,List<Map<String,String>>>();
		String queryString = "Select selectId from SelectTag group by selectId";
		List<String> selectTagList = find(queryString, null);
		for (String selectTag : selectTagList) {
			String selectId=selectTag;
			List<Map<String, String>> reMap=this.getSelectOptions(selectId);
			dicMap.put(selectId, reMap);
		}
		return dicMap;
	}

	@Override
	public List<Map<String, String>> getSelectNameBySelectId(String selectId) {
		String queryString = "from SelectTag where selectId=? and status=1 order by labelSeq";
		List<SelectTag> selectTag = find(queryString, selectId);
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (int i = 0; i < selectTag.size() ; i++) {
			SelectTag st = selectTag.get(i);
			Map<String, String> map = new HashMap<String, String>();
			map.put(st.getValue(),st.getLabel());
			list.add(map);
		}
		return list;
	}

}

